package com.siam.package_rider.mapper;

import java.math.BigDecimal;
import java.util.List;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.siam.package_merchant.model.param.MerchantWithdrawRecordParam;
import org.apache.ibatis.annotations.Param;

import com.siam.package_rider.entity.TbRiderWithdrawRecord;
import com.siam.package_rider.model.param.TbRiderWithdrawRecordParam;
import org.apache.ibatis.annotations.Select;

/**
 * ---------------------------
 * 骑手提现记录表 (TbRiderWithdrawRecordMapper)         
 * ---------------------------
 * 作者：  高品
 * 时间：  2025-03-29 18:55:18
 * ---------------------------
 */
public interface TbRiderWithdrawRecordMapper extends BaseMapper<TbRiderWithdrawRecord> {

    /**
     * 基础分页查询
     * @param param
     * @return
     */    
    Page<TbRiderWithdrawRecord> page(@Param("page") Page page, @Param("param") TbRiderWithdrawRecordParam param);

    @Select("<script>select IFNULL(sum(mwa.actual_amount), 0) from tb_rider_withdraw_record mwa " +
            "<where> 1=1 and audit_status = 2 " +
            "<if test=\"riderWithdrawRecord.id != null\"> AND mwa.id = #{riderWithdrawRecord.id} </if>" +
            "<if test=\"riderWithdrawRecord.riderId != null\"> AND mwa.rider_id = #{riderWithdrawRecord.riderId} </if>" +
            "<if test=\"riderWithdrawRecord.withdrawAmount != null\"> AND mwa.withdraw_amount = #{riderWithdrawRecord.withdrawAmount} </if>" +
            "<if test=\"riderWithdrawRecord.platformFee != null\"> AND mwa.platform_fee = #{riderWithdrawRecord.platformFee} </if>" +
            "<if test=\"riderWithdrawRecord.auditStatus != null and riderWithdrawRecord.auditStatus != -1\"> AND mwa.audit_status = #{riderWithdrawRecord.auditStatus} </if>" +
            "<if test=\"riderWithdrawRecord.auditReason != null and riderWithdrawRecord.auditReason != ''\"> AND mwa.audit_reason like '%${riderWithdrawRecord.auditReason}' </if>" +
            "<if test=\"riderWithdrawRecord.startCreateTime != null\"> AND DATE_FORMAT(mwa.create_time, '%Y/%m/%d') &gt;= #{riderWithdrawRecord.startCreateTime} </if>" +
            "<if test=\"riderWithdrawRecord.endCreateTime != null\"> AND DATE_FORMAT(mwa.create_time, '%Y/%m/%d') &lt;= #{riderWithdrawRecord.endCreateTime} </if>" +
            "</where> order by mwa.id desc" +
            "</script>")
    BigDecimal statisticalAmountByWithdrawalSuccessful(@Param("riderWithdrawRecord") TbRiderWithdrawRecordParam riderWithdrawRecord);
}